package com.matrix.app.mvc.project.member.repository;

import com.matrix.app.mvc.project.member.data.MemberPo;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;
import org.springframework.stereotype.Repository;

/**
 * 项目成员持久层
 *
 * Copyright © 海平面工作室 版权所有
 *
 * @Author: Leo
 * @Create: 2025/06/01 18:30
 * @Since 1.0
 */
@Repository
public interface MemberRepository extends JpaRepository<MemberPo, Long>, JpaSpecificationExecutor<MemberPo> {
    /**
     * 按条件分页查询成员
     * @param searchKey 姓名或电话
     * @param role 角色
     * @param sex 性别
     * @param pageable 分页参数
     * @return 分页结果
     */
    @Query("SELECT m FROM MemberPo m WHERE ((:searchKey IS NULL OR m.name LIKE %:searchKey%) OR (:searchKey IS NULL OR m.phone LIKE %:searchKey%)) AND (:role IS NULL OR m.role = :role) AND (:sex IS NULL OR m.sex = :sex)")
    Page<MemberPo> findByConditions(@Param("searchKey") String searchKey, @Param("role") String role, @Param("sex") String sex, Pageable pageable);
} 